package com.study.flink.scala.day01_wc

import org.apache.flink.api.scala._

object BatchWordCount {

  def main(args: Array[String]): Unit = {

    val env = ExecutionEnvironment.getExecutionEnvironment
    val lines: DataSet[String] = env.readTextFile("dir/day01/source/words.txt")

    val words = lines.flatMap(_.split(" "))
    val wordAndOne = words.map((_, 1))
    val grouped: GroupedDataSet[(String, Int)] = wordAndOne.groupBy(0)
    val summed: AggregateDataSet[(String, Int)] = grouped.sum(1)

    summed.print()
    summed.writeAsText("dir/day01/result").setParallelism(2)

    env.execute("BatchWordCount-scala")

  }

}
